package poo.util;

public class Matrice {

	static int[] copia(int[][] m) {
		/** copia tutti gli elementi della matrice in un array */
		int dimensione = m.length * m[0].length;
		int[] v = new int[dimensione];

		int h = 0;
		while (h < dimensione) {
			for (int i = 0; i < m.length; i++) {
				for (int j = 0; j < m[0].length; j++) {

					v[h] = m[i][j];
					h++;
				}
			}

		}
		return v;
	}

	public static int[] diagonaleSecondaria(int[][] m) {
		int[] v = new int[m.length];
		 for(int i=0, j=m.length-1; i<m.length; i++,j--){
		 v[i] = m[i][j];
		 }
		return v;

	}

	public static int[] diagonalePrincipale(int[][] m) {
		int[] v = new int[m.length];
		for (int i = 0; i < m.length; i++) {
			v[i] = m[i][i];
		}
		return v;
	}

	public static void main(String[] args) {

		int[][] m = { { 6, 2, 11, 9, 12 }, { 8, 14, 10, 3, 1 },
				{ 14, 21, 11, 2, 2 }, { 8, 1, 13, 1, 7 }, { 10, 17, 13, 10, 4 } };
		
		int[] a = copia(m);
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i] + " ");
		}
		
		System.out.println("diag princ");
		int[] v = diagonalePrincipale(m);
		for (int i = 0; i < v.length; i++) {
			System.out.print(v[i] + " ");
		}
		
		System.out.println("diag sec");
		int[] d = diagonaleSecondaria(m);
		for (int i = 0; i < d.length; i++) {
			System.out.print(d[i] + " ");
		}
	}
}
